
$().ready(function () {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#login").click(function () {

        var username = $("#username").val().trim();
        var password =$("#password").val().trim();
        var accountType=$("#accountType").val().trim();
        $("#signUpForm span").remove();

        if(username ===""||username == null){
            $("#username").after('<span class="text-danger">'+icon+'请输入登陆账号</span>');
        }
        if(password ===""||password == null){
            $("#password").after('<span class="text-danger">'+icon+'请输入密码</span>');
        }
        if(username !==""&& password !== ""){
            console.log(accountType);
            var data = {"account":username,"password":hex_md5(password),"adminType":accountType};
            $.ajax({
                url:"/platform/adminLogin",
                type:"post",
                async:false,
                data:JSON.stringify(data),
                dataType:"json",
                contentType:"application/json; charset=utf-8",
                success: function (data) {
                    if(data.code ==="200"){
                        sessionStorage.setItem("adminInfo",JSON.stringify(data.result));
                        if(accountType=="1"||accountType=="2"){
                            window.location.href="/platform/index.html";
                        }
                        if(accountType=="3"){
                            window.location.href="/platform/agent/index.html";
                        }
                    }else{
                        $("#forgot span").remove();
                        $("#forgot").after('<span class="text-danger">'+data.message+'</span>');
                    }
                },
                error:function (data) {
                    $("#forgot span").remove();
                    console.error("request error",data);
                    $("#forgot").after('<span class="text-danger">系统繁忙，请稍后再试</span>');
                }
            })
        }
    })

});
